package ch.zbw.pra.sysventory.dataaccess.dataAccessObject;

import java.io.Serializable;
import java.util.List;

import org.springframework.context.ApplicationContext;

import ch.zbw.pra.sysventory.database.jdbcTemplate.HardDiskJDBCTemplate;
import ch.zbw.pra.sysventory.model.HardDisk;
import ch.zbw.pra.sysventory.utils.DatabaseUtils;

/**
 * Bereitet Daten für den Zugriff auf die Datenbank im DatabaseLayer auf
 * 
 * @author Ralph Koster & Roberto Lucas
 */

public class HardDiskDataAccessObject implements Serializable {

	private static final long serialVersionUID = 1515038118268902580L;
	
	private ApplicationContext context;
	private HardDiskJDBCTemplate hardDiskJDBCTemplate;
	
	public HardDiskDataAccessObject() {
		context = DatabaseUtils.getContext();
		hardDiskJDBCTemplate = (HardDiskJDBCTemplate)context.getBean("hardDisk");
	}

	public List<HardDisk> getAllHardDisksFromDatabase() {
		List<HardDisk> hardDisks = hardDiskJDBCTemplate.listHardDisks();
		return hardDisks;
	}

	public List<HardDisk> getAllHardDisksFromComputer(Integer computerId) {
		List<HardDisk> hardDisks = hardDiskJDBCTemplate.listHardDisksFromComputer(computerId);
		return hardDisks;
	}

	public Integer writeHardDiskToDatabase(HardDisk hardDisk, Integer computerId) {
		Integer hardDiskId = hardDiskJDBCTemplate.insertHardDisk(hardDisk, computerId);
		return hardDiskId;
	}

	public void writeHardDisksToDatabase(List<HardDisk> hardDisks,
			Integer computerId) {
		for(HardDisk hardDisk : hardDisks){
			hardDiskJDBCTemplate.insertHardDisk(hardDisk, computerId);
		}
	}
}
